package br.com.cicero.designpatterns.command.absfactory;

import java.io.FileInputStream;
import java.util.Properties;

import br.com.cicero.designpatterns.command.BaseCommand;

public class CommandFactory2 implements CommandFactory {
	
	Properties apelidosComandos = new Properties();
	
	public CommandFactory2() {
		
		try {
			
			this.apelidosComandos.load(new FileInputStream("commands.properties"));
			
			
		} catch (Exception e) {
			
			e.printStackTrace();
			
		}
				
	}
	
	public BaseCommand create(String name) {
		
		BaseCommand command = null;
		String stringClasse = this.apelidosComandos.getProperty(name);
		
		try {
			
			Class classe = Class.forName(stringClasse);
			Object object = classe.newInstance();
			command = (BaseCommand) object;
			
			
		} catch (Exception e) {
			
			e.printStackTrace();
			
		}
				
		return command;
	}
	
}
